package com.gosophia.resource.action;

import java.net.URLEncoder;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.exception.CommonException;
import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.commons.web.logAnnotation.LogRecord;
import com.gosophia.resourcePermission.dto.RuleDTO;
import com.gosophia.resourcePermission.ws.ResourcePermissionWebService;
import com.gosophia.rulevalidator.InvalidExpressionException;
import com.gosophia.util.RequestResultUtil;
import com.opensymphony.xwork2.ActionContext;

/**
 * 修改规则
 * @author zhao_yanfang
 *
 */

@Controller("updateRuleAction")
@Scope("prototype")
public class UpdateRuleAction extends BaseSupportAction{
	private static final Log logger = LogFactory
	.getLog(ShowResourcePageAction.class);
	private RuleDTO ruleDTO;
	@Autowired
	private ResourcePermissionWebService resourcePermissionWebService;
	@LogRecord(eventAction="数据权限规则-更新规则",eventTarget="ruleDTO")
	public String _execute() throws Exception {
		logger.info("修改资源集,资源编号:"+ruleDTO.getRuleId());
		try {
			resourcePermissionWebService.updateRule(ruleDTO);
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw new CommonException(e.getMessage(), "JC2_REP_C_1");
		}
		super.getRequestResult().setMessage("修改规则成功");
		super.getRequestResult().setRsltCode("0");
		ActionContext.getContext().getSession().put("_lastOpResult", super.getRequestResult());
		return SUCCESS;
	}
	public RuleDTO getRuleDTO() {
		return ruleDTO;
	}
	public void setRuleDTO(RuleDTO ruleDTO) {
		this.ruleDTO = ruleDTO;
	}
	
}
